<template>
  <FormView
    v-model="entity"

    :title="!entity.id ? '新建盘点事项' : '修改盘点事项'"
    :toolbar-attrs="{ buttons: ['back', 'save', 'cancel'] }"
    :toolbar-listeners="{ save: persist }">
    <template #toolbar-right>
    </template>
    <FormHolder ref="form" label-width="110px" :model="entity"  :disabled="entity.status === '1'">
      <FormItemGroup block-title="基本信息">
        <FormInput v-model="entity.subject" prop="subject" label="事项名称" :span="24" required max-length="255"/>

        <FormSelect v-model="entity.status" prop="status" label="状态" dict-type="work_item_status" disabled :span="12"/>
        <FormSelect v-model="entity.level" prop="level" label="紧急程度" :span="12" dict-type="work_item_level_type" required max-length="255"/>

        <FormInput v-model="entity.assignedName" prop="assignedName" label="处理人" :span="12" required
                   max-length="255"  @focus="focusAssigned"/>
        <FormInputNumber v-model="entity.orderNo" :min="0" prop="orderNo" label="排序" :span="12"/>

        <FormTextarea v-model="entity.description" prop="description" label="事项说明" :span="12" max-length="2000"/>

        <UserPicker
          v-if="visibleSelectUser"
          :reserve-position-on-close="false"
          close-on-click-modal
          :visible.sync="visibleSelectUser"
          @confirm="getUserData"/>
      </FormItemGroup>
      <FormItemGroup :gutter="0" block-title="资产清单">
        <WorkItemListAsset v-if="entity.id"  :work-item-id="entity.id" :inventory-task-id="entity.formId" :work-item-status="entity.status" style="height: 500px;"/>
      </FormItemGroup>
      <FormItemGroup :gutter="0" block-title="催办信息">

      </FormItemGroup>
    </FormHolder>
  </FormView>
</template>

<script>
import {create, load, save, update} from '@/api/workItem/workItem'
import form from '@/vue/mixin/form'
import WorkItemListAsset from '@/module/workItem/WorkItemListAsset'

export default {
  name: 'WorkItemForm',
  relativeViewId: 'WorkItem',
  components: {
    WorkItemListAsset
  },
  mixins: [form],
  props: {
    formId: {
      type: String,
      default: '-1'
    }
  },
  data() {
    return {
      entity: {
        id: '',
        unid: '',
        createId: '',
        createBy: '',
        createTime: '',
        deptId: '',
        deptFullname: '',
        assignedId: '',
        assignedName: '',
        assignedDeptId: '',
        assignedDeptFullName: '',
        updateBy: '',
        updateTime: '',
        tenantId: '',
        delFlag: '',
        status: '',
        formId: '',
        subject: '',
        description: '',
        orderNo: null,
        level: '',
        reminderType: '',
        urgentId: '',
        parentId: ''
      },
      visibleSelectUser: false
    }
  },
  methods: {
    create(){
      return create(this.formId)
    },
    load,
    save,
    update,
    getUserData(rows) {
      const user = rows[0]
      this.entity.assignedId = user.id
      this.entity.assignedName = user.name
      this.entity.assignedDeptId = user.deptId // 单位名称
      this.entity.assignedDeptFullName = user.deptFullname // 单位名称
    },
    focusAssigned() {
      this.visibleSelectUser = true
    }
  }
}
</script>
